import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'

@Component({
  selector: 'cp-popup',
  templateUrl: './popup.component.html',
  styleUrls: ['./popup.component.scss']
})
export class PopupComponent implements OnInit {
  @Input() maskClick = false
  @Input() otherClass
  @Input() _show = false
  @Input()
  get show() {
    return this._show
  }
  set show(value) {
    this._show = value
    this.showChange.emit(value)
    if (value) {
      let t = window.scrollY
      document.body.style.position = 'fixed'
      document.body.style.top = t + 'px'
    } else {
      document.body.style.position = ''
      document.body.style.top = ''
    }
  }
  @Output() showChange = new EventEmitter()
  @Output() onMaskClick = new EventEmitter()

  constructor() {}

  ngOnInit() {}

  handleClose(e) {
    // 点击的是遮罩层且遮罩层可点击的话，就关闭弹窗
    if (e.target.id === 'mask' && this.maskClick) {
      this.show = false
      this.onMaskClick.emit()
    }
  }
}
